package cn.ibizlab.odoo.core.odoo_base.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Ibase_language_export;
import cn.ibizlab.odoo.core.odoo_base.domain.Base_language_export;
import cn.ibizlab.odoo.core.odoo_base.filter.Base_language_exportSearchContext;
import cn.ibizlab.odoo.core.odoo_base.service.IBase_language_exportService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[语言输出] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Base_language_exportServiceImpl implements IBase_language_exportService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Ibase_language_exportClientService base_language_exportClientService;

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Ibase_language_export clientModel = base_language_exportClientService.createModel();
        clientModel.setId(id);
        base_language_exportClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public Base_language_export get(Integer id) {
        Ibase_language_export clientModel = base_language_exportClientService.createModel();
        clientModel.setId(id);
        base_language_exportClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Base_language_export get(Base_language_export base_language_export) {
        Base_language_export retbase_language_export = this.get(base_language_export.getId()) ;
    	BeanCopier copier=BeanCopier.create(retbase_language_export.getClass(), base_language_export.getClass(), false);
        copier.copy(retbase_language_export, base_language_export, null);
        return base_language_export ;
    }

    @Override
    public boolean update(Base_language_export base_language_export) {
        boolean bOk = false ;
        Ibase_language_export clientModel = this.convert2Model(base_language_export,null);
        base_language_exportClientService.update(clientModel) ;
        this.convert2Domain(clientModel,base_language_export) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //base_language_exportClientService.removeBatch(base_language_exports) ;

    }

    @Override
    public void updateBatch(List<Base_language_export> base_language_exports, int batchSize) {

        //base_language_exportClientService.updateBatch(base_language_exports,batchSize) ;

    }

    @Override
    public boolean create(Base_language_export base_language_export) {
        boolean bOk = false ;
        Ibase_language_export clientModel = this.convert2Model(base_language_export,null);
        base_language_exportClientService.create(clientModel) ;
        this.convert2Domain(clientModel,base_language_export);
        bOk = true ;

        return bOk ;
    }

    @Override
    public void createBatch(List<Base_language_export> base_language_exports, int batchSize) {

                        //base_language_exportClientService.createBatch(base_language_exports,batchSize) ;

    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Base_language_export> searchDefault(Base_language_exportSearchContext context) {
        List<Base_language_export> list = new ArrayList<Base_language_export>();
        Page<cn.ibizlab.odoo.core.client.model.Ibase_language_export> clientModelList = base_language_exportClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ibase_language_export clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Base_language_export>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据用户查询
     */
    @Override
    public Page<Base_language_export> selectByOdoo_create(Integer id){
        Base_language_exportSearchContext context = new Base_language_exportSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Base_language_export> list = new ArrayList<Base_language_export>();
        Page<cn.ibizlab.odoo.core.client.model.Ibase_language_export> clientModelList = base_language_exportClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ibase_language_export clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Base_language_export>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Base_language_export> selectByOdoo_write(Integer id){
        Base_language_exportSearchContext context = new Base_language_exportSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Base_language_export> list = new ArrayList<Base_language_export>();
        Page<cn.ibizlab.odoo.core.client.model.Ibase_language_export> clientModelList = base_language_exportClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ibase_language_export clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Base_language_export>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Ibase_language_export convert2Model(Base_language_export domain , Ibase_language_export model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = base_language_exportClientService.createModel() ;
        }

         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getLangDirtyFlag())
            model.setLang(domain.getLang());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getFormatDirtyFlag())
            model.setFormat(domain.getFormat());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getDataDirtyFlag())
            model.setData(domain.getData());
         if(domain.getModulesDirtyFlag())
            model.setModules(domain.getModules());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getNameDirtyFlag())
            model.setName(domain.getName());
         if(domain.getStateDirtyFlag())
            model.setState(domain.getState());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
        return model ;
    }

    public Base_language_export convert2Domain( Ibase_language_export model ,Base_language_export domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Base_language_export();
        }

        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getLangDirtyFlag())
            domain.setLang(model.getLang());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getFormatDirtyFlag())
            domain.setFormat(model.getFormat());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getDataDirtyFlag())
            domain.setData(model.getData());
        if(model.getModulesDirtyFlag())
            domain.setModules(model.getModules());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getNameDirtyFlag())
            domain.setName(model.getName());
        if(model.getStateDirtyFlag())
            domain.setState(model.getState());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        return domain ;
    }


}
